<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>博客详情_frm</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/news_detail.css"/>
</head>
<body>
	<div class="aui-content">
        <div id="main">
                <h1 id="title"></h1>
                <label id="info"></label>
            	<div id="content" class="TextContent">
            	</div>
        </div>
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/OSChinaApi.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
	var pageParam, imageUrls, img_index;
	apiready = function(){
		pageParam = api.pageParam;
		getDetail( pageParam.id );
	};
	
	function getDetail( id ){
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '加载中...',
		    text: '',
		    modal: true
		});
	
		imageUrls = [];
		img_index = 0;
		
		var url = OpenAPI.blog_detail + '?id=' + id;
		api.ajax({
		    url: url,
		    method: 'get',
		    timeout: 30,
		    dataType: 'text',
		    returnAll:false,
		},function(ret,err){
			api.hideProgress();
		    if (ret) {
				var trans = api.require('trans');
				trans.parse({
				    data:ret
				},function(ret,err){
				    if(ret) {
				    	// 设置 win 的收藏图标状态
						api.execScript({
						    name: 'blog_detail_win',
						    script: 'set_favorite_ico( '+ret.oschina.blog.favorite+', '+ret.oschina.blog.id+' );  set_blogcomment_button( '+ret.oschina.blog.id+', '+ret.oschina.blog.commentCount+' );'
						});
				    
				    	// 把各个内容添加到页面中
				    	$api.text($api.byId('title'), ret.oschina.blog.title);
						$api.html($api.byId('info'), ret.oschina.blog.author+'　 <em>'+friendly_time(ret.oschina.blog.pubDate)+'</em>');
				    	var body = strip_tags(ret.oschina.blog.body, '<style><img><p><ul><li><ol><table><pre><code><h1><h2><h3>');
				    	
						// 图片浏览处理
						body.replace(/<img.*?src=\"(.*?)\"[^>]*>/ig, function(a, b) {
							if( b.indexOf("plugins/emoticons") < 0 ){
								body = body.replace(a, "<img class='image' onclick='imageBrowser("+img_index+")' src='"+b+"' />");
								imageUrls.push(b);
							    img_index++;
							}else{
								body = body.replace(a, "<img class='emoticons' src='"+b+"' />");
							}
						});
				    	
				    	$api.html($api.byId('content'), body);
				    	
				    	changeContentFontSize();
				    }else{
				        log(err.msg);
				    }
				});
		    }else {
		        log('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode);
		    	showAjaxErrMsg(err.code);
		    }
		});
	}
	
	// 浏览图片
	function imageBrowser(index){
			if("undefined" == typeof index){
				index = 0;
			}
			var obj = api.require('imageBrowser');
			obj.openImages({
			    imageUrls: imageUrls,
			    showList: false,
			    activeIndex: index
			});
	}

</script>
</html>